package com.gh.controller;

import com.gh.common.result.R;
import com.gh.service.FileApiService;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Author Eric
 * @Date 2021/9/11 10:52
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/oss")
public class FileApiController {

    @Autowired
    private FileApiService fileApiService;

    @PostMapping("/uploadFile")
    public R uploadFile(@RequestParam("file") MultipartFile file,
                        @RequestParam("module") String module) {
        String path = fileApiService.uploadFile(file, module);
        return R.ok().message("文件上传成功").data("pathUrl", path);
    }

    @DeleteMapping("/remove")
    public R removeFile(@RequestParam("url") String url){
        fileApiService.removeFile(url);
        return R.ok().message("删除成功");

    }
}
